package com.youdianstar.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.youdianstar.app.common.util.DateUtil
import com.youdianstar.app.common.util.MathUtil
import com.youdianstar.app.R
import com.youdianstar.app.databinding.LayoutItemRecordOpBinding
import com.youdianstar.app.entity.OpTransaction
import com.youdianstar.app.util.DataAppManager


/**
 * File: TransOPAdapter
 * Author: 82149 Create: 2023/8/2 16:11
 * Changes (from 2023/8/2)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
class TransOPAdapter(val mContext: Context, val dataList: List<OpTransaction>) : RecyclerView.Adapter<TransOPAdapter.ListHolder>(){

    class ListHolder(val binding : LayoutItemRecordOpBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListHolder {
        return ListHolder(LayoutItemRecordOpBinding.inflate(LayoutInflater.from(parent.context), parent, false))
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ListHolder, position: Int) {
        dataList[position].let { item ->
            holder.binding.tvOrderId.text = mContext.getString(R.string.order_orderID)+": "+item.orderIdTx()
            //日期
            holder.binding.tvTime.text = DateUtil.getOrderTime(item.createTime)
            val symbolStr = DataAppManager.instance.symbolTx()
            //流水类型：1-订单分成 2-调整 3-退款
            if (item.type==3){
                holder.binding.tvAmount.text = "-$symbolStr ${MathUtil.round(item.amountAbs())}"
                holder.binding.tvDes.text = mContext.getString(R.string.shop_rentalRefund)
            }else{
                holder.binding.tvAmount.text = "+$symbolStr ${MathUtil.round(item.amount)}"
                holder.binding.tvDes.text = mContext.getString(R.string.shop_rentalProfit)
            }
        }
    }

}